Texture InputTexture;
Texture Mask;

sampler inputTexture = sampler_state 
{ 
    texture = <InputTexture>; 
    magfilter = LINEAR; 
    minfilter = LINEAR; 
    mipfilter = LINEAR; 
};

sampler mask = sampler_state 
{ 
    texture = <Mask>; 
    magfilter = LINEAR; 
    minfilter = LINEAR; 
    mipfilter = LINEAR; 
};
 
struct VS_OUTPUT
{
	float4 Position	: POSITION;
	float2 TexCoords : TEXCOORD0;
};
 
float4 Mask_PS (VS_OUTPUT Input) : COLOR0
{
	float4 color = tex2D(inputTexture, Input.TexCoords);
	float4 mask_color = tex2D(mask, Input.TexCoords);
	
	float mask_intensity = (mask_color.r + mask_color.g + mask_color.b)/3.0;
	
	color.a = mask_intensity;
	
	return color;
}
 
technique Mask
{
	pass P0
	{
		PixelShader = compile ps_2_0 Mask_PS();
	}
}